package com.pj.lib.auraClient;

import android.content.Context;
import android.content.SharedPreferences;

public class AuraPreferences {
	public final static String NAME = "auraPrefs";
	
	public final static String KEY_LOGIN = "lib_login";
	public final static String KEY_PASSWORD = "lib_password";
	public final static String KEY_USER_ID = "lib_user_id";
	public final static String KEY_LOGGED = "lib_logged";
	public final static String KEY_ADDRESS = "lib_address";
	public final static String KEY_PORT = "lib_port";
	
	private static SharedPreferences sSettings;
	
	public static void updateString(Context context, String key, String value) {
		initSettings(context);
		SharedPreferences.Editor editor = sSettings.edit();
		editor.putString(key, value);
		editor.commit();
	}
	
	public static String getString(Context context, String key) {
		initSettings(context);
		return sSettings.getString(key, "");
	}
	
	public static String getString(Context context, String key, String defVal) {
		initSettings(context);
		return sSettings.getString(key, defVal);
	}
	
	public static void updateInt(Context context, String key, int value) {
		initSettings(context);
		SharedPreferences.Editor editor = sSettings.edit();
		editor.putInt(key, value);
		editor.commit();
	}
	
	public static int getInt(Context context, String key) {
		initSettings(context);
		return sSettings.getInt(key, -1);
	}
	
	public static int getString(Context context, String key, int defVal) {
		initSettings(context);
		return sSettings.getInt(key, defVal);
	}
	
	private static void initSettings(Context context) {
		if(sSettings == null) {
			sSettings = context.getSharedPreferences(NAME, Context.MODE_PRIVATE);
		}
	}
}
